package com.example.victory.service;

import com.alibaba.fastjson.JSONObject;
import com.example.victory.swagger.handler.AppCustomerOverallTradeApiDelegate;
import com.example.victory.swagger.model.*;
import com.example.victory.utils.JsonUtils;
import com.cgws.fintech.sdk.api.inner.crmapi.model.ApiRequesFsdp;
import com.cgws.fintech.sdk.api.inner.crmapi.model.ApiRequesFsdpData;
import com.cgws.fintech.sdk.api.inner.crmapi.model.ApiResponseFsdp;
import com.example.victory.common.web.ServiceHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class AppCustomerOverAllTrade implements AppCustomerOverallTradeApiDelegate {

    @Autowired
    private  InnerOverAllTradeFsdpService innerOverAllTradeFsdpService;

    private String getCustomerId(ApiRequestCustomerId param){
        ServiceHelper.checkDataNotNull(param.getData(),"param.data");
        ServiceHelper.checkDataNotNull(param.getData().getCustomerId(),"param.data.customerId");
        return  param.getData().getCustomerId();
    }

    @Override
    public ResponseEntity<ApiResponseCustomerOverAllTradeNormal> getCustomerOverAllTradeCredit(ApiRequestCustomerId param) {
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("customerId",getCustomerId(param));
        ResponseEntity<ApiResponseFsdp> fsdpResponseEntity=innerOverAllTradeFsdpService.getCustomerOverAllTradeCredit(new ApiRequesFsdp().data(new ApiRequesFsdpData().params(jsonObject.toJSONString())));
        ApiResponseCustomerOverAllTradeNormalData normal= JsonUtils.getResultEntity(fsdpResponseEntity,ApiResponseCustomerOverAllTradeNormalData.class);
        return ResponseEntity.ok(new ApiResponseCustomerOverAllTradeNormal().data(normal));
    }

    @Override
    public ResponseEntity<ApiResponseCustomerOverAllTradeNormal> getCustomerOverAllTradeNormal(ApiRequestCustomerId param) {
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("customerId",getCustomerId(param));
        ResponseEntity<ApiResponseFsdp> fsdpResponseEntity=innerOverAllTradeFsdpService.getCustomerOverAllTradeNormal(new ApiRequesFsdp().data(new ApiRequesFsdpData().params(jsonObject.toJSONString())));
        ApiResponseCustomerOverAllTradeNormalData normal=JsonUtils.getResultEntity(fsdpResponseEntity,ApiResponseCustomerOverAllTradeNormalData.class);
        return ResponseEntity.ok(new ApiResponseCustomerOverAllTradeNormal().data(normal));
    }

    @Override
    public ResponseEntity<ApiResponseCustomerOverAllTradeOption> getCustomerOverAllTradeOption(ApiRequestCustomerId param) {
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("customerId",getCustomerId(param));
        ResponseEntity<ApiResponseFsdp> fsdpResponseEntity=innerOverAllTradeFsdpService.getCustomerOverAllTradeOption(new ApiRequesFsdp().data(new ApiRequesFsdpData().params(jsonObject.toJSONString())));
        ApiResponseCustomerOverAllTradeOptionData option=JsonUtils.getResultEntity(fsdpResponseEntity,ApiResponseCustomerOverAllTradeOptionData.class);
        return ResponseEntity.ok(new ApiResponseCustomerOverAllTradeOption().data(option));
    }

    @Override
    public ResponseEntity<ApiResponseCustomerOverAllTradeOtc> getCustomerOverAllTradeOtc(ApiRequestCustomerId param) {
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("customerId",getCustomerId(param));
        ResponseEntity<ApiResponseFsdp> fsdpResponseEntity=innerOverAllTradeFsdpService.getCustomerOverAllTradeOtc(new ApiRequesFsdp().data(new ApiRequesFsdpData().params(jsonObject.toJSONString())));
        ApiResponseCustomerOverAllTradeOtcData otc=JsonUtils.getResultEntity(fsdpResponseEntity,ApiResponseCustomerOverAllTradeOtcData.class);
        return ResponseEntity.ok(new ApiResponseCustomerOverAllTradeOtc().data(otc));
    }

    @Override
    public ResponseEntity<ApiResponseCustomerOverAllTradeOverview> getCustomerOverAllTradeOverview(ApiRequestCustomerId param) {
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("customerId",getCustomerId(param));
        ResponseEntity<ApiResponseFsdp> fsdpResponseEntity=innerOverAllTradeFsdpService.getCustomerOverAllTradeOverview(new ApiRequesFsdp().data(new ApiRequesFsdpData().params(jsonObject.toJSONString())));
        ApiResponseCustomerOverAllTradeOverviewData view=JsonUtils.getResultEntity(fsdpResponseEntity,ApiResponseCustomerOverAllTradeOverviewData.class);
        return ResponseEntity.ok(new ApiResponseCustomerOverAllTradeOverview().data(view));
    }
}
